package com.kenliang.javase.spi;

import sun.jvm.hotspot.debugger.cdbg.basic.BasicVoidType;

import java.util.Iterator;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.stream.StreamSupport;

/**
 * @author KenLiang
 * @description:
 * @date Created in 5:57 PM 2019/8/15.
 */
public class SerializerService {
    public void getObjectSerializer() {
        ServiceLoader<ObjectSerializer> serializers = ServiceLoader.load(ObjectSerializer.class);

//        final Optional<ObjectSerializer> serializer = StreamSupport.stream(serializers.spliterator(), false)
//                .findFirst();
//        System.out.println(serializer.get().getSchemeName());
//        return serializer.orElse(new JavaSerializer());
//        return serializer.get();

        Iterator<ObjectSerializer> iterator = serializers.iterator();
        while (iterator != null && iterator.hasNext()) {
            System.out.println(iterator.next().getSchemeName());
        }
    }
}
